﻿using System.Collections.Generic;
using System.Linq;
using DAL.Core.Models;
using DAL.Core.Repository;

namespace DAL.Core.DTO.Implementation
{
    public abstract class StandardPostData : IRepository<PostData, vwPostData>
    {
        protected xBotDataEntities context;

        protected StandardPostData()
        {
            context = new xBotDataEntities();
        }

        public void Create(PostData entity)
        {
            context.CreatePostData(entity.Domain,
                                   entity.BannedBy,
                                   entity.Subreddit,
                                   entity.SelfTextHtml,
                                   entity.SelfText,
                                   entity.Likes,
                                   entity.SecureMedia,
                                   entity.Saved,
                                   entity.ID,
                                   entity.SecureMediaEmbed,
                                   entity.Clicked,
                                   entity.Stickied,
                                   entity.Author,
                                   entity.Score,
                                   entity.ApprovedBy,
                                   entity.Over18,
                                   entity.Hidden,
                                   entity.Thumbnail,
                                   entity.SubredditID,
                                   entity.Edited,
                                   entity.LinkFlairCssClass,
                                   entity.AuthorFlairCssClass,
                                   entity.Downs,
                                   entity.IsSelf,
                                   entity.Permalink,
                                   entity.Name,
                                   entity.Created,
                                   entity.URL,
                                   entity.AuthorFlairText,
                                   entity.Title,
                                   entity.CreatedUTC,
                                   entity.LinkFlairText,
                                   entity.Ups,
                                   entity.NumComments,
                                   entity.NumReports,
                                   entity.Distinguished,
                                   entity.MediaEmbed,
                                   entity.Media);
        }

        public List<vwPostData> Read()
        {
            return context.vwPostData.ToList();
        }

        public void Update(PostData entity)
        {
            context.UpdatePostData(entity.DataID,
                                   entity.Domain,
                                   entity.BannedBy,
                                   entity.Subreddit,
                                   entity.SelfTextHtml,
                                   entity.SelfText,
                                   entity.Likes,
                                   entity.SecureMedia,
                                   entity.Saved,
                                   entity.ID,
                                   entity.SecureMediaEmbed,
                                   entity.Clicked,
                                   entity.Stickied,
                                   entity.Author,
                                   entity.Score,
                                   entity.ApprovedBy,
                                   entity.Over18,
                                   entity.Hidden,
                                   entity.Thumbnail,
                                   entity.SubredditID,
                                   entity.Edited,
                                   entity.LinkFlairCssClass,
                                   entity.AuthorFlairCssClass,
                                   entity.Downs,
                                   entity.IsSelf,
                                   entity.Permalink,
                                   entity.Name,
                                   entity.Created,
                                   entity.URL,
                                   entity.AuthorFlairText,
                                   entity.Title,
                                   entity.CreatedUTC,
                                   entity.LinkFlairText,
                                   entity.Ups,
                                   entity.NumComments,
                                   entity.NumReports,
                                   entity.Distinguished,
                                   entity.MediaEmbed,
                                   entity.Media);            
        }

        public void Delete(PostData entity)
        {
            context.DeletePostData(entity.DataID);
        }
    }
}
